public class Usermanager {
    ...

    private void addUsers() throws Exception {
        // open Session
        Session session = HibernateUtil.currentSession();
        // start Transaction
        Transaction tx = session.beginTransaction();
        // loop for 100,000 and insert 100,000 records
        for (int i = 0; i<100000; i++>) {
            // creat `User` entity
            User user = new User();
            user.setName("xxxxx" + i);
            user.setAge(i);
            user.setNationality("china");

            // Cache `User` entity at `Session` level
            session.save(user);
            // when 累加器's size is 20's fold, flush the data in session to database; and then clear session Cache
            if (i % 20 == 0) {
                session.flush();
                session.clear();
            }
        }
        // commit Transaction
        tx.commit();
        // close Transaction
        HibernateUtil.closeSession();
    }

    ...
}